package cn.antho.org.controller;

import cn.antho.basic.anno.PreAuthorize;
import cn.antho.basic.util.AjaxResult;
import cn.antho.basic.util.PageList;
import cn.antho.org.domain.Log;
import cn.antho.org.query.LogQuery;
import cn.antho.org.service.ILogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/log")
@PreAuthorize
public class LogController {

    @Autowired
    private ILogService ILogService;

    // 删
    @DeleteMapping("/{id}")
    @PreAuthorize(name = "根据id删除", sn = "log:delete")
    public AjaxResult delete(@PathVariable("id") Long id) {
        ILogService.delete(id);
        return AjaxResult.me().success();
    }

    // 查所有
    @GetMapping
    public List<Log> findAll() {
        return ILogService.findAll();
    }

    // 查单个
    @GetMapping("/{id}")
    @PreAuthorize(name = "根据id查询日志",sn = "log:findById")
    public Log findById(@PathVariable("id") Long id) {
        return ILogService.findById(id);
    }

    // 分页查询
    @PostMapping
    @PreAuthorize(name = "分页查询日志",sn = "log:queryByPage")
    public PageList<Log> queryByPage(@RequestBody LogQuery query) {
        return ILogService.queryByPage(query);
    }

    @PatchMapping
    @PreAuthorize(name = "批量删除日志",sn = "log:batchDel")
    public AjaxResult batchDel(@RequestBody List<Long> ids) {
        ILogService.batchDel(ids);
        return AjaxResult.me().success();
    }

}

